package com.yan.kfgl.service.biz.spring;

import java.util.Date;

import com.yan.kfgl.common.MNUtil;
import com.yan.kfgl.model.MNUser;
import com.yan.kfgl.model.vo.ShownUser;
import com.yan.kfgl.service.biz.facade.UserService;
import com.yan.kfgl.service.dao.facade.UserDaoService;

public class UserServiceSpringImpl implements UserService{

	private UserDaoService userDaoService;
	
	@Override
	public ShownUser findUserByNameAndPassword(ShownUser su , String password) {
		MNUser mu = MNUtil.formatShownUserToMNUser(su, password);
		mu = userDaoService.findUserByNameAndPassword(mu);
		su = MNUtil.parseMNUserToShownUser(mu);
		return su;
	}

	@Override
	public boolean saveOrUpdate(ShownUser user , String password) {
		if(user != null && user.getName() != null && !"".equals(user.getName().trim()) && password != null && !"".equals(password.trim())){
			MNUser mu = MNUtil.formatShownUserToMNUser(user, password);
			mu.setUpdateTimeForHis(new Date());
			userDaoService.saveOrUpdate(mu);
			return true;
		}else{
			return false;
		}
	}

	@Override
	public ShownUser findShownUserByName(ShownUser su) {
		if(su != null && su.getName() != null && !"".equals(su.getName().trim())){
			MNUser user = new MNUser();
			user.setName(su.getName());
			user = userDaoService.findUserByName(user);
			su = MNUtil.parseMNUserToShownUser(user);
		}
		return su;
	}

	public UserDaoService getUserDaoService() {
		return userDaoService;
	}

	public void setUserDaoService(UserDaoService userDaoService) {
		this.userDaoService = userDaoService;
	}

}
